#include "Graph.h"
#include <list>

struct PolyVertex
{
	D3DXVECTOR2 pos;
	PolyVertex* next;
	PolyVertex* prev;
	Vertex* Vertex;
	bool hasVertex = false;
};

class Poly
{
public:
	Poly();
	Poly(D3DXVECTOR2*, int);
	void Append(D3DXVECTOR2);
	void Remove(int);
	void Insert(int, D3DXVECTOR2);
	int Size() 
	{
		int s = 0;
		PolyVertex* c = first;
		do
		{
			s++;
			c = c->next;
		} while (c != first);
		return s; 
	}
	bool IsValid() { return valid; }
	PolyVertex* First() { return first; }
	PolyVertex* Last() { return last; }
	bool ContainsPoint(D3DXVECTOR2);
	Poly AddBorder(float);
	PolyVertex* first;
	int size;
	void Delete();

private:
	PolyVertex* last;
	bool valid;
};

class Mesh
{
public:
	Mesh() {};
	Mesh(Poly);
	void AddPoly(Poly);
	void UpdateGraph();
	bool GetPath(Vector2, Vector2, std::vector<Vector2>*);
	Graph* GetNavGraph() { return &NavGraph; }
	Poly* GetBorder() { return &Border; }
	std::vector<Poly>* GetHoles() { return &Holes; }
	bool LoS(Vector2 a, Vector2 b);

private:
	Poly Border;
	std::vector<Poly> Holes;
	Graph NavGraph;
};